/*
 License
 
 Copyright © 2012 Kevin Kimmich
 
 Permission is hereby granted, free of charge, to any person obtaining a copy
 of this software and associated documentation files (the "Software"), to deal
 in the Software without restriction, including without limitation the rights to 
 use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
 the Software, and to permit persons to whom the Software is furnished to do so, 
 subject to the following conditions:
 
 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
 INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
 PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
 FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */

/**
 @file
 Variable length string implementation. This is largely deprecated in favor of the
 stream, so DON'T use it for new code!
 */
#ifndef _stringbuffer_h
#define _stringbuffer_h

#ifdef __cplusplus
extern "C" {
#endif


//
// Variable length string manipulation functions.
//

//create a string buffer object.
stringbuffer* sb_create(void);
void sb_init(stringbuffer* sb, char* cb);

//destroy the string buffer object and its buffer, to keep the buffer and lose the object
//just free(sb), and retain the sb->data pointer.
void sb_destroy(stringbuffer *sb);
//copy the string buffer
stringbuffer* sb_copy(stringbuffer* dst,stringbuffer* src);
//add the null terminated string cb to sb.
void sb_add_data(stringbuffer *sb, const char *cb);
//copy some string data to sb->data
void sb_copy_data(stringbuffer *sb, char *cb , int length);
//initialize the buffer with a string, this is used on a stringbuffer object that has already
//been allocated.
bool sb_init_buffer(stringbuffer *sb, const char *cb);
//like printf, but more limited, formats are added as needed. Mostly, just for
//splicing two stringbuffers together.
void sb_sprintf(stringbuffer *sb, const char* format, ...);
//keep the buffer as allocated, and set length to zero.
void sb_truncate(stringbuffer* sb);
//retrieve the sb->data pointer.
char *sb_get_buffer(stringbuffer* sb);
//retrieve the length of the string in sb->data.
unsigned int sb_get_length( stringbuffer* sb);
//free just the data pointer, but keep the buffer object
void sb_delete_buffer(stringbuffer* sb);
//compare to strings if a=b, return 0, else non-zero
int sb_compare(stringbuffer *a , stringbuffer *b);
//replace the stringbuffer data buffer with buf
void sb_replace(stringbuffer* sb, char* buf, int len);
	

#ifdef __cplusplus
}
#endif


#endif
